home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 6 / QRZ Ham Radio Callsign Database - Volume 6.iso / pc / files / dsp / 56100tar.z / 56100tar / 56100 / g722 / h221fix / h221tx.asm < prev    next >
Encoding:
Assembly Source File  |  1992-04-15  |  21.4 KB  |  644 lines

  1. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. ;;+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +
  3. ;;+ +                                      + +
  4. ;;+ +       This is the beginning of the H221 transmit state machine       + +
  5. ;;+ +                                      + +
  6. ;;+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +
  7. ;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8.  
  9.         ;list        ; enable transmit state listing
  10.  
  11. ;;***************************************************************
  12. ;;*                                *
  13. ;;*    transmit state 0  :  This state is the first in the     *
  14. ;;*    H221 transmit sequence for each submultiframe and     *
  15. ;;*    multiframe stage.                    *
  16. ;;*                                *
  17. ;;*    Date    :    20/9/90 & 15/10/90            *
  18. ;;*    Version    :    1.0 & 1.1                *
  19. ;;*                                *
  20. ;;***************************************************************
  21.  
  22. ;;    Data Storage structure required        ; tx_ref_count_ptr ds    1
  23.                         ; tx_0_val       dc    15
  24.                         ;           dc    1120
  25.                         ;           dc    0
  26.                         ; mf_count_store   ds    1
  27.                         ; mf_count       ds    1
  28.  
  29. tx_state_0    move    #tx_ref_count_ptr,r3    ; restore current isdn count
  30.                         ; compare pointer
  31.         move    x:isdn_count_tx,b    ; current transmit count in b
  32.         
  33.         move    x:(r3)+,r2        ; restore count ptr for state
  34.         move    x:(r3)+,y0        ; mf max. count in y0 for later
  35.         move    x:(r3)+,y1        ; term. alarm ref. count in y1
  36.         move    x:(r2)+n2,x1 x:(r3)+,x0    ; mf count disabled tx in x0
  37.                         ; submultiframe ref count in x1
  38.         tst    b    x:(r3)+,a    ; is the tx count zero
  39.                         ; get last mf count value in a
  40.         bne    <not_end_mf        ; to allow first entry into
  41.                         ; state machine                    
  42.         move    #tx_count,r2        ; restore smf count pointer
  43.  
  44.         move    x:(r3),a        ; recall last mf count value
  45.         dec24    a    x:(r2)+n2,x1    ; decrement multiframe count
  46.         tmi    y0,a            ; is result negative ? if yes
  47.                         ; restore max. count. & update
  48.         move    x:control_word,y0    ; reference count value in x1
  49.         bftstl    #$0004,y0        ; store updated count
  50.         tcs    x0,a            ; multiframe counting enabled ?
  51.                         ; no then load a with 0
  52.         move    a1,x:(r3)        ; store new mf count value
  53.         
  54. not_end_mf    cmp    x1,b            ; end of odd smframe yet ?
  55.         bne    <end_tx_0        ; no, then finish state
  56.         cmp    y1,b            ; terminal alarm bit count in y1
  57.         bne    <not_term_alarm        ; if not same count then branch
  58.         
  59.         move    x:is_shft,b        ; term alarm count true, remove
  60.         ror    b            ; current tx byte lsb & replace
  61.         move    x:control_word,x0    ; test terminal alarm bit in
  62.         bftsth    #$0040,x0        ; control word
  63.         bra    <end_alarm_tx        ; finish current state
  64.  
  65. not_term_alarm    move    x:is_shft,b        ; H221 being enabled then remove
  66.         ror    b            ; current tx byte lsb and relace
  67.         bftsth    #$0001,a1        ; with H221 multiframe count bit
  68.  
  69. end_alarm_tx    rol    b            ; rotate carry into b1 lsb    
  70.         move    b1,x:is_shft        ; store updated isdn byte
  71.         asr    a    (r3)-        ; shift mf word in preparation
  72.         move    a1,x:(r3)        ; for the next submultiframe
  73.                         ; dec r3 to point at 
  74.                         ; x:mf_count_store & store 
  75.                         ; shifted count
  76.         move    #faw_state_a,r1        ; new next state
  77.         move    r2,x:tx_ref_count_ptr    ; store pointer
  78.  
  79. end_tx_0    rts
  80.         
  81. ;;***************************************************************
  82. ;;*                                *
  83. ;;*    Frame Alignment State    :    This state transmits    *
  84. ;;*    the frame alignment bits, in order, for each even     *
  85. ;;*     frame of the H221 recommendation.            *
  86. ;;*                                *
  87. ;;*    Date    :    20/9/90    & 15/10/90            *
  88. ;;*    Version    :    1.0 & 1.1                *
  89. ;;*                                *
  90. ;;***************************************************************
  91.  
  92. faw_state_a    move    #faw_state_0,r1
  93.         move    #faw_state_1,x0
  94.         move    x0,x:faw_state_ptr
  95.         
  96. faw_state_0    move    x:faw_state_ptr,r3    ; restore faw tx ptr into r3
  97.         move    #is_shft,r2        ; current isdn tx byte
  98.         jsr    r3            ; next faw tx state
  99.         move    r3,x:faw_state_ptr    ; store next faw state ptr
  100.         
  101.         rts
  102.  
  103. faw_state_1    move    #faw_state_2,r3        ; next faw state
  104.         bfclr    #$0001,x:(r2)        ; clear the current isdn lsb
  105.         rts                
  106.  
  107. faw_state_2    move    #faw_state_3,r3        ; next faw state
  108.         bfclr    #$0001,x:(r2)        ; clear the current isdn lsb
  109.         rts                    
  110.  
  111. faw_state_3    move    #faw_state_4,r3        ; next faw state
  112.         bfset    #$0001,x:(r2)        ; set the current isdn lsb
  113.         rts                    
  114.  
  115. faw_state_4    move    #faw_state_5,r3        ; next faw state
  116.         bfset    #$0001,x:(r2)        ; set the current isdn lsb
  117.         rts                    
  118.  
  119. faw_state_5    move    #faw_state_6,r3        ; next faw state
  120.         bfclr    #$0001,x:(r2)        ; clear the current isdn lsb
  121.         rts                
  122.  
  123. faw_state_6    move    #faw_state_7,r3        ; next faw state
  124.         bfset    #$0001,x:(r2)        ; set the current isdn lsb
  125.         rts                    
  126.  
  127. faw_state_7    move    #bas_state_a,r1        ; next state
  128.         bfset    #$0001,x:(r2)        ; set the current isdn lsb
  129.         rts                    
  130.  
  131. ;;***************************************************************
  132. ;;*                                *
  133. ;;*    Bas State    :   This state takes the decoded    *
  134. ;;*    bit-rate-allocation signal and transmits the BAS    *
  135. ;;*    code into its relevant position within the H221        *
  136. ;;*    structure. The BAS data should be stored in the     *
  137. ;;*    following format :                    *
  138. ;;*                                *
  139. ;;*                b b b b    b b b b         *
  140. ;;*    MSB    0 0 0 0    0 0 0 0    a a a a    a a a a            *
  141. ;;*                s s s s    s s s s            *
  142. ;;*                                *
  143. ;;*                7 6 5 4    3 2 1 0            *
  144. ;;*                                *
  145. ;;*        <------- storage word -------->            *
  146. ;;*               BAS_DATA                *
  147. ;;*                                *
  148. ;;*    Date    :    21/9/90                    *
  149. ;;*    Version    :    1.0                    *
  150. ;;*                                *
  151. ;;***************************************************************
  152.  
  153. bas_state_a    move    #bas_state_0,r1        ; new next state
  154.         move    #bas_state_1,x0        ; set up subroutine pointers
  155.         move    x0,x:bas_state_ptr
  156.  
  157. bas_state_0    move    x:bas_state_ptr,r3    ; recall pointer
  158.                     
  159.         move    x:is_shft,a        ; current isdn byte in a
  160.         ror    a            ; rotate lsb into carry
  161.         move    x:bas_data,x0        ; get current BAS word
  162.         
  163.         jsr    r3            ; jump to latest BAS tx state
  164.  
  165.         rol    a            ; rotate test result into 
  166.                         ; isdn data lsb
  167.         move    a1,x:is_shft        ; restore isdn byte
  168.         move    r3,x:bas_state_ptr    ; store next subroutine ptr
  169.         rts
  170.  
  171. bas_state_1    move    #bas_state_2,r3        ; new next state
  172.         bftsth    #$0001,x0        ; test BAS lsb
  173.         rts
  174.  
  175. bas_state_2    move    #bas_state_3,r3        ; new next state
  176.         bftsth    #$0008,x0        ; test BAS b3
  177.         rts
  178.  
  179. bas_state_3    move    #bas_state_4,r3        ; new next state
  180.         bftsth    #$0004,x0        ; test BAS b2
  181.         rts
  182.  
  183. bas_state_4    move    #bas_state_5,r3        ; new next state
  184.         bftsth    #$0002,x0        ; test BAS b1
  185.         rts
  186.  
  187. bas_state_5    move    #bas_state_6,r3        ; new next state
  188.         bftsth    #$0020,x0        ; test BAS b5
  189.         rts
  190.  
  191. bas_state_6    move    #bas_state_7,r3        ; new next state
  192.         bftsth    #$0010,x0        ; test BAS b4
  193.         rts
  194.  
  195. bas_state_7    move    #bas_state_8,r3        ; new next state
  196.         bftsth    #$0040,x0        ; test BAS b6
  197.         rts
  198.  
  199. bas_state_8    move    #erc_calc_0,r1        ; new next state
  200.         bftsth    #$0080,x0        ; test BAS msb
  201.         rts
  202.                 
  203. ;;***********************************************************************
  204. ;;*                                    *
  205. ;;*    Erc Calc State 0 : this state takes the current BAS        *
  206. ;;*    data value and rearranges it for subsequent calculation        *
  207. ;;*    of the error correction bits which are to be transmitted    *
  208. ;;*    in the next H221 frame.    The BAS data is rearraged into the    *
  209. ;;*    following format :                        *
  210. ;;*                                    *
  211. ;;*            b b b b    b b b b                    *
  212. ;;*            a a a a    a a a a                    *
  213. ;;*            s s s s    s s s s    0 0 0 0    0 0 0 0            *
  214. ;;*                                    *
  215. ;;*            0 1 2 3    4 5 6 7                    *
  216. ;;*                                    *
  217. ;;*            <------ erc calc store ------->            *
  218. ;;*                BAS/ERC_store                *
  219. ;;*                                    *
  220. ;;*    Date    :    26/9/90                        *
  221. ;;*    Version    :    1.0                        *
  222. ;;*                                    *
  223. ;;***********************************************************************
  224.  
  225. erc_calc_0    move    x:bas_data,a        ; get current BAS word
  226.         clr    b            ; prepare b acc. for store
  227.         do    #8,bas_re_arrange            
  228.         ror    a            ; bas bit into carry
  229.         rol    b            ; carry into b1 lsb
  230. bas_re_arrange    asr4    b            
  231.         asr4    b            ; shift re-arranged BAS bits
  232.         move    b0,x:bas_store        ; into b0 and store
  233.         move    #erc_calc_1,r1        ; new next state
  234.         
  235.         rts
  236.  
  237. ;;**************************************************************************
  238. ;;*                                       *
  239. ;;*    Erc Calc State 1    :     This state takes the latest       *
  240. ;;*    rearranged bas data and calculates the ERC error correction        *
  241. ;;*    bits for transmission in the next frame. The structure used       *
  242. ;;*    is as indicated below :                           *
  243. ;;*                                       *
  244. ;;*                             b b b b    b    b b b       *
  245. ;;*                                a a a a    a    a a a       *
  246. ;;*    0 0 0 0   0 0 0    0    y y y y    y y y y    s s s s    s    s s s       *
  247. ;;*                                       *
  248. ;;*                 8 7 6 5    4 3 2 1       0 1 2 3    4    5 6 7       *
  249. ;;*                                       *
  250. ;;*    <---------------  a1  ---------------->    <-------------  a0  --  *
  251. ;;*                                       *
  252. ;;*    For the correct polynomial division (i.e. generator polynomial     *
  253. ;;*    g(x) == x8 + x7 + x6 + x4 + x2 + x + 1) the equations required        *
  254. ;;*    are                                   *
  255. ;;*    +  == modulo 2 addition        @ y1 == y8 + bas 0           *
  256. ;;*    @  == next clock value        @ y2 == y8 + y1               *
  257. ;;*    y8 == output            @ y3 == y8 + y2               *
  258. ;;*                    @ y5 == y8 + y4               *
  259. ;;*                    @ y7 == y8 + y6               *
  260. ;;*                    @ y8 == y8 + y7               *
  261. ;;*                                       *
  262. ;;**************************************************************************
  263.  
  264. erc_calc_1    move    #bas_store,r2
  265.         move    #erc_calc_2,r1
  266.         move    r2,x:(r2+7)        ; store pointer
  267.         move    x:(r2),a        ; set up a accumulator for erc 
  268.         move    a0,x:(r2+4)        ; clear reference count
  269.         move    a0,x:(r2+5)        ; store a accumulator set-up
  270.         move    a1,x:(r2+6)        ; for next state
  271.         
  272.         rts
  273.         
  274. erc_calc_2    move    x:r2_temp,r2        ; recall pointer
  275.                         ; the storage structure used
  276.                         ; for this routine is as below
  277.                         ; ****************************
  278.                         ;
  279.                         ; bas_store    ds    1
  280.                         ; mask        dc    $00d7
  281.                         ; erc_ref_val    dc    0
  282.                         ;        dc    16
  283.                         ; count_check    ds    1
  284.                         ; temp_erc    ds    2
  285.                         ; r2_temp    ds    1
  286.                         ; erc_store    ds    1
  287.                         ;
  288.                         ;*****************************
  289.         clr    a            ; clear accumulators for loop
  290.         clr    b    x:(r2+1),x0    ; load generator polynomial mask
  291.                         ; into x0
  292.         move    x:(r2+5),a        ; restore crc division data into
  293.         move    x:(r2+6),a0        ; accumulator a
  294.         
  295.         bfclr    #$0080,a1        ; test & clear last output bit,
  296.         tcc    x0,b            ; the result sets current mask 
  297.         asl    a    b,y1        ; in b. shift crc before eor'ing                        ; and new mask in y1
  298.         eor    y1,a    x:(r2+4),b    ; update crc storage bits and
  299.                         ; get loop count value in b
  300.         move    x:(r2+3),y0        ; max. loop count of 16 in y0
  301.         move    a1,x:(r2+5)        ; store crc division data into
  302.                         ; memory
  303.         inc24    b    a0,x:(r2+6)    ; increment loop count compare
  304.         cmp    y0,b    b,x:(r2+4)    ; with max and save new count
  305.         blt    <end_erc_calc        ; if not complete, repeat state
  306.         
  307.         move    a1,x:(r2+8)        ; store calculated ERC bits
  308.         move    #tx_odd_state,r1    ; new next state pointer
  309.         
  310. end_erc_calc    rts
  311.         
  312. ;;****************************************************************************
  313. ;;*                                         *
  314. ;;*    Transmit Odd State    :     This state tranmits the multiframe   *
  315. ;;*    alignment bits in their correct order in bit position 1 of every     *
  316. ;;*    odd frame                                 *
  317. ;;*                                         *
  318. ;;*    Date    :    26/9/90                             *
  319. ;;*    Version    :    1.0                             *
  320. ;;*                                         *
  321. ;;****************************************************************************
  322.  
  323. tx_odd_state    move    x:tx_ref_count_ptr,r2    ; latest ref. count pointer
  324.         move    x:isdn_count_tx,b    ; current isdn count in b
  325.         move    x:(r2+9),x0        ; odd frame ref. count in x0
  326.         cmp    x0,b            ; compare ref. and actual and
  327.         blt    <end_tx_odd_state    ; if not odd frame yet repeat 
  328.                         ; state
  329.         move    x:mfaw_data,y0        ; stored multiframe align word
  330.         move    x:mfaw_store,a        ; H221 loop variable multiframe 
  331.                         ; word
  332.         move    #80,x1            ; are we at frame 1 again ?
  333.         cmp    x1,b    x:(r2)+,y1    ; compare and update pointer 
  334.                         ; for next time
  335.         teq    y0,a            ; yes, refresh multiframe word 
  336.                         ; in a
  337.         move    x:is_shft,b        ; current isdn byte in b
  338.         ror    b            ; shift lsb into carry
  339.         bftsth    #$0001,a1        ; test the current multiframe
  340.         rol    b            ; alignment bit and rotate carry
  341.         move    b1,x:is_shft        ; into isdn byte lsb, which sets
  342.         asr    a            ; or resets it accordingly
  343.         move    a1,x:mfaw_store        ; store the current multiframe 
  344.                         ; variable
  345.         move    r2,x:tx_ref_count_ptr    ; store the update pointer
  346.         move    #faw_end_state,r1    ; next state pointer
  347.         
  348. end_tx_odd_state    rts
  349.         
  350. ;;*****************************************************************************
  351. ;;*                                          *
  352. ;;*    Faw Complete state    :    This state completes the frame           *
  353. ;;*    alignment word for the current submultiframe. All it has to do is     *
  354. ;;*    set the lsb of the current isdn transmit byte.                  *
  355. ;;*                                          *
  356. ;;*    Date    :    26/9/90                              *
  357. ;;*    Version    :    1.0                              *
  358. ;;*                                          *
  359. ;;*****************************************************************************
  360.  
  361. faw_end_state     move    #is_shft,r2        ; current isdn byte ptr in r2
  362.         
  363.         move     #mfaw_faw_valid,r1    ; next state    
  364.         
  365.         bfset    #$0001,x:(r2)        ; set lsb of byte
  366.  
  367.         rts
  368.         
  369. ;;*****************************************************************************
  370. ;;*                                          *
  371. ;;*    MFAW FAW Valid State    :    This state checks whether the latest  *
  372. ;;*    multiframe and frame alignment signals have been received correctly.  *
  373. ;;*    The current isdn tx lsb will be set accordingly. This transmission    *
  374. ;;*    corresponds to bit A of the H221 protocol.                  *
  375. ;;*                                          *
  376. ;;*    Date    :    27/9/90                              *
  377. ;;*    Version    :    1.0                              *
  378. ;;*                                          *
  379. ;;*****************************************************************************
  380.  
  381. mfaw_faw_valid    move    #crc_tx_test,r1        ; next state
  382.         move    x:control_word,y0    ; control word in x0
  383.         move    x:is_shft,a        ; current isdn byte
  384.         inc    a            ; set a0 lsb to '1'
  385.         ror    a    a0,x0        ; lsb in carry & eor mask in x0
  386.         bftsth    #$6000,y0        ; test for frame and
  387.         rol    a            ; multiframe alignment, new a1
  388.         eor    x0,a            ; change H221 lsb in a1        
  389.         move    a1,x:is_shft        ; and store new isdn lsb
  390.         
  391.         rts
  392.         
  393. ;;****************************************************************************
  394. ;;*                                         *
  395. ;;*    CRC Tx Test State    :    This state transmits the relevant    *
  396. ;;*    crc bits in their respective positions in the current frame         *
  397. ;;*                                         *
  398. ;;*    Date    :    26/9/90 & 14/10/90                     *
  399. ;;*    Version    :    1.0 & 1.1                         *
  400. ;;*                                         *
  401. ;;****************************************************************************
  402.  
  403. crc_tx_test    move    #control_word,r2    ; control word pointer in r2
  404.         move    #is_shft,r3        ; current isdn byte pointer in 
  405.                         ; r3    
  406.         bftsth    #$0002,x:(r2)        ; test crc_tx enable in control
  407.                         ; word, if disabled then send
  408.         bcs    crc_tx_enabled        ; appropriate H221 data
  409.         
  410.         bfclr    #$0001,x:(r3)        ; bit E set to zero
  411.         
  412.         move    #disable_crc_0,r1    ; next state
  413.         move    #disable_crc_1,x0    ; next crc disabled pointer
  414.         move    x0,x:disable_crc_ptr
  415.  
  416.         rts
  417.         
  418. disable_crc_0    move    x:disable_crc_ptr,r3    ; restore next disable crc ptr
  419.         move    #is_shft,r2        ; current isdn byte in x1
  420.         jsr    r3            ; jump to next disable crc state
  421.         move    r3,x:disable_crc_ptr    ; store pointer
  422.         
  423.         rts
  424.         
  425. disable_crc_1    move    #disable_crc_2,r3    ; next disable state
  426.         bfset    #$0001,x:(r2)        ; crc bit set to '1'
  427.         rts
  428.  
  429. disable_crc_2    move    #disable_crc_3,r3    ; next disable state
  430.         bfset    #$0001,x:(r2)        ; crc bit set to '1'
  431.         rts
  432.  
  433. disable_crc_3    move    #disable_crc_4,r3    ; next disable state
  434.         bfset    #$0001,x:(r2)        ; crc bit set to '1'
  435.         rts
  436.  
  437. disable_crc_4    move    #erc_tx_state,r1    ; next disable state
  438.         bfset    #$0001,x:(r2)        ; crc bit set to '1'
  439.         rts
  440.         
  441. crc_tx_enabled    move    #enable_crc_0,r1    ; next state    
  442.         move    x:is_shft,a        ; current isdn byte in x1, lsb
  443.         ror    a            ; of current isdn byte in carry
  444.                         ; test if the last received crc
  445.         bftsth    #$0800,x:(r2)        ; was in error. ( control word
  446.                         ; pointer still in r2 )
  447.         rol    a            ; replace current isdn lsb with
  448.         move    a1,x:is_shft        ; result of test and store
  449.         
  450.         move    #enable_crc_1,x0    ; set up next crc tx state ptr.
  451.         move    x0,x:enable_crc_ptr
  452.         
  453.         rts                ; updated isdn transmit byte
  454.         
  455. enable_crc_0    move    x:enable_crc_ptr,r3    ; get crc tx state pointer    
  456.         move    x:is_shft,a        ; current isdn byte in x1
  457.         ror    a            ; lsb of current isdn byte
  458.         move    x:tx_crc_data,x0    ; in carry    
  459.         jsr    r3
  460.         rol    a            ; replace current isdn lsb with
  461.         move    a1,x:is_shft        ; result of test and store 
  462.         move    r3,x:enable_crc_ptr    ; store next crc tx state ptr.
  463.  
  464.         rts
  465.         
  466. enable_crc_1    move    #enable_crc_2,r3    ; set up next crc state pointer
  467.         bftsth    #$0080,x0        ; test crc msb
  468.         rts
  469.         
  470. enable_crc_2    move    #enable_crc_3,r3    ; set up next crc state pointer
  471.         bftsth    #$0040,x0        ; test crc bit
  472.         rts
  473.         
  474. enable_crc_3    move    #enable_crc_4,r3    ; set up next crc state pointer
  475.         bftsth    #$0020,x0        ; test crc bit
  476.         rts
  477.         
  478. enable_crc_4    move    #erc_tx_state,r1    ; set up next tx state pointer
  479.         bftsth    #$0010,x0        ; test crc lsb
  480.         rts
  481.         
  482. ;;*****************************************************************************
  483. ;;*                                          *
  484. ;;*    ERC Transmit State    :      This is the final state of the      *
  485. ;;*    odd frame transmit H221 sequence. It takes the result of the last     *
  486. ;;*    BAS division crc and transmits the calculated ERC bits in their       *
  487. ;;*    respective time slots within the H221 structure. The stucture of      *
  488. ;;*    the ERC storage is as below :                          *
  489. ;;*                                          *
  490. ;;*                    e e e e    e e e e                  *
  491. ;;*                    r r r r    r r r r                  *
  492. ;;*            x x x x    x x x x    c c c c    c c c c                  *
  493. ;;*                                          *
  494. ;;*                    0 1 2 3    4 5 6 7                  *
  495. ;;*                                          *
  496. ;;*            <-------- ERC Storage -------->                  *
  497. ;;*                   erc_store                      *
  498. ;;*                                          *
  499. ;;*    Date    :    27/9/90    &12/10/90                      *
  500. ;;*    Version    :    1.0 & 1.1                          *
  501. ;;*                                          *
  502. ;;*****************************************************************************
  503.  
  504. erc_tx_state    move    #erc_tx_0,r1        ; set-up pointers and storage
  505.         move    #erc_tx_1,x0
  506.         move    x0,x:erc_state_ptr
  507.         
  508. erc_tx_0    move    x:erc_state_ptr,r3    ; restore erc state pointer
  509.         move    x:is_shft,a        ; current isdn byte in a 
  510.         ror    a            ; lsb into carry
  511.         move    x:erc_store,x0        ; latest calc. ERC bits in x0 
  512.         jsr    r3            ; jump to latest erc tx state
  513.         rol    a            ; and shift result into a1
  514.         move    a1,x:is_shft        ; re-store modified isdn byte
  515.         move    r3,x:erc_state_ptr    ; store erc state pointer
  516.         
  517.         rts
  518.         
  519. erc_tx_1    move    #erc_tx_2,r3        ; next erc tx state ptr in r3
  520.         bftsth    #$0020,x0        ; test bit in erc store
  521.         rts
  522.  
  523. erc_tx_2    move    #erc_tx_3,r3        ; next erc tx state ptr in r3
  524.         bftsth    #$0040,x0        ; test bit in erc store
  525.         rts
  526.  
  527. erc_tx_3    move    #erc_tx_4,r3        ; next erc tx state ptr in r3
  528.         bftsth    #$0080,x0        ; test bit in erc store
  529.         rts
  530.  
  531. erc_tx_4    move    #erc_tx_5,r3        ; next erc tx state ptr in r3
  532.         bftsth    #$0008,x0        ; test bit in erc store
  533.         rts
  534.  
  535. erc_tx_5    move    #erc_tx_6,r3        ; next erc tx state ptr in r3
  536.         bftsth    #$0010,x0        ; test bit in erc store
  537.         rts
  538.  
  539. erc_tx_6    move    #erc_tx_7,r3        ; next erc tx state ptr in r3
  540.         bftsth    #$0004,x0        ; test bit in erc store
  541.         rts
  542.  
  543. erc_tx_7    move    #erc_tx_8,r3        ; next erc tx state ptr in r3
  544.         bftsth    #$0002,x0        ; test bit in erc store
  545.         rts
  546.  
  547. erc_tx_8    move    #tx_state_0,r1        ; next tx state ptr in r1
  548.         bftsth    #$0001,x0        ; test bit in erc store
  549.         rts
  550.             
  551. ;;*****************************************************************************
  552. ;;*                                          *
  553. ;;*    CRC performance check for the ISDN 64 kbps channel              *
  554. ;;*    Data structure used ;                                  *
  555. ;;*                                          *
  556. ;;*  |        a1         |         a1            |          a0           |  *
  557. ;;*                                          *
  558. ;;*    0   0   0   y    x xd1xd2xd3xd4xd5xd6xd7    x xd1xd2xd3xd4xd5xd6xd7    *
  559. ;;*             *       *                          *
  560. ;;*    output states       penultimate ISDN data            last data rx           *
  561. ;;*        y               ir(N-1)                    ir(N)             *
  562. ;;*                                              *
  563. ;;*        d     == single state delay                      *
  564. ;;*        *     == bits to be x'ored                      *
  565. ;;*        y4    == output and crc result msb                  *
  566. ;;*        @    == after next clock i.e. next left shift          *
  567. ;;*                                          *
  568. ;;*    Equations governing the crc operation are as below :              *
  569. ;;*                                          *
  570. ;;*        @ x    ==     y + xd1                          *
  571. ;;*        @ xd3    ==    y + xd4                          *
  572. ;;*                                          *
  573. ;;*    The CRC equation for the ISDN line check is    :              *
  574. ;;*                                          *
  575. ;;*        y(d)/x(d) == g(d) == d4/(1+d+d4)                  *
  576. ;;*                                          *
  577. ;;*        Date    :    27/9/90                          *
  578. ;;*                29/4/91                          *
  579. ;;*        Version    :    1.8                          *
  580. ;;*                1.9                          *
  581. ;;*                                            *
  582. ;;*****************************************************************************
  583.  
  584. ;;  Optimised storage set_up  :            isdn_count_tx    ds    1
  585. ;;                        tx_crc_store    ds    1
  586. ;;                                dc    0
  587. ;;                                dc    8
  588. ;;                        is        ds    1
  589. ;;                        tx_crc_value_2    dc    12
  590. ;;                                dc    $0090
  591. ;;                        tx_crc_data    ds    1
  592.  
  593. crc_tx        move    #isdn_count_tx,r3    ; optimised storage pointer
  594.         move    x:tx_crc_cnt_ptr,r2    ; crc count comparison pointer
  595.  
  596.         move    x:(r3)+,b        ; current isdn count in b
  597.         move    x:(r3)+,a        ; last crc storage value in a
  598.         move    x:(r3)+,y0        ; zero reference in y0
  599.         move    x:(r2)+n2,x1 x:(r3)+,x0    ; current ref. count in x1
  600.                         ; default loop count in x0
  601.         cmp    x1,b    x:(r2+50),x1    ; first byte of new 
  602.                         ; submultiframe ?
  603.                         ; last byte of smf, count in x1
  604.         bne    <tx_smf_not_done
  605.         cmp    y0,b    x:(r2)+,y1    ; first byte of multiframe ?
  606.                         ; update reference counter in y1
  607.         bne    <tx_cnt_not_zero    ; no, then branch
  608.         
  609.         move    #crc_count,r2        ; yes, restore count pointer,
  610.         
  611. tx_cnt_not_zero    move    a1,x:tx_crc_data    ; store final crc result,
  612.         move    x:is_shft,a        ; isdn data byte in a
  613.                         ; this provides the d4 multiply
  614.         bra    <crc_loop_tx        ; function in crc generator eqn.
  615.                         ; wait for next intrupt for crc
  616. tx_smf_not_done    move    x:(r3)+,a0        ; new isdn data in here to a0
  617.         move    x:(r2+34),y1        ; crc bit tx, lower window count
  618.         cmp    y1,b    x:(r2+42),y1    ; is current count in window
  619.         blt    <out_window_tx        ; less than, then branch
  620.         cmp    y1,b            ; upper window reference compare
  621.         bgt    <out_window_tx        ; greater than, then branch
  622.  
  623.         bfclr    #$0100,a0        ; if in crc window clear latest
  624.                         ; isdn lsb bit then perform crc
  625. out_window_tx    cmp    x1,b    x:(r3)+,y0    ; last count in present block ?
  626.                         ; update pointer for next time.
  627.         tne    x0,b            ; appropriate loop count
  628.         teq    y0,b            ; in b1
  629.         swap    b            ; loop count in b0, b1 is clear
  630.         tfr3    b,y0    x:(r3)+,x0    ; clear y0 for crc loop,
  631.                         ; crc mask 2 in x0
  632.         do    b0,crc_loop_tx        ; do loop b0 times
  633.  
  634.         bfclr    #$0080,a1        ; test & clear last output,
  635.         tcc    x0,b            ; set mask as a result of test
  636.         asl    a    b,y1        ; new mask in y1, shift bits
  637.         eor    y1,a    y0,b        ; before eor, perform modulo 2
  638.                         ; of a1 bits and clear b
  639. crc_loop_tx    move    a1,x:tx_crc_store    ; save CRC data for next rx
  640.         move    r2,x:tx_crc_cnt_ptr    ; save reference count pointer
  641.         
  642.         rts
  643.     
  644.         ;nolist